<template>
  <var-overlay v-model:show="dialog" :close-on-click-overlay="false" :style="{ backgroundColor: 'transparent' }" style="align-items: flex-end;">
    <div class="relative-position" style="width: 100vw;">
      <div class="agreement-box">
        <div class="agreement-box-text">
          阅读并同意协议
          <img @click="close" style="width: 16px;height: 16px;" src="~/assets/images/public/close.png" alt="">
        </div>
        <!-- <div class="agreement-box-text" style="font-size: 12px; color: #666;">
          请仔细阅读并同意以下协议
        </div> -->
        <div class="style-bg"></div>
        <div class="change-tab">
          <div class="main-box">
            <slot>
              <iframe style="width: 100%; flex: auto;height: 50vh;" scrolling="yes" :src="webSrc" frameborder="0"></iframe>
            </slot>
            <div style="width: 319px; margin: 10px 0;">
              <q-btn :label="btnName" padding="none none" unelevated rounded @click="submit" :loading="loading"
                class="full-width" style="
                  background-color: #1277FF;
                  color: #fff;
                  height: 52px;
                  font-size: 15px;
                  font-weight: 600;
                " />
            </div>
          </div>
          <div class="main-bg-box"></div>
        </div>
      </div>
    </div>
  </var-overlay>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { Show } from './CustomAgreementDialog';
import { useWxHook } from 'src/hooks/wx_hooks';
import { useRoute, useRouter } from 'vue-router';
import { useProtocolLink } from 'src/config/protocol_link';
const dialog = ref(false);
const loading = ref(false);
const webSrc = ref("")
const router = useRouter();
const route = useRoute();
const props = defineProps({
  btnName: {
    type: String,
    default: '同意协议并继续'
  }
})
const emit = defineEmits(['confirm', 'close'])
const show: Show = async (src: string) => {
  webSrc.value = src
  dialog.value = true;
};
const submit = () => {
  close()
  emit('confirm')
};

const close = () => {
  dialog.value = false;
  emit('close')
};
defineExpose({ show });
</script>

<style lang="scss" scoped>
.close-btn {
  position: absolute;
  right: 0;
  top: 0;
  margin: 16px;
}
.agreement-box {
  background-image: url(src/assets/images/public/popup-top-2.png);
  background-color: #fff;
  background-repeat: no-repeat;
  background-size: 100% auto;
  border-radius: 20px 20px 0 0;
  overflow: hidden;
  height: 100%;
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  .style-bg{
    position: absolute;
    width: 100%;
    height: 182px;
    top: 60px;
    background: linear-gradient( 180deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.95) 10%, #fff 100%);
  }
  .change-tab{
    width: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    margin-top: 17px;
    flex: auto;
    .main-bg-box{
      background: #e9eef4;
      position: absolute;
      width: 100%;
      height: 50px;
      top: 56px;
      z-index: 10;
    }
    .main-box{
      display: flex;
      flex-direction: column;
      align-items: center;
      position: relative;
      background: rgb(255,255,255);
      z-index: 11;
      padding: 6px 13px;
      flex: 1 0 auto;
      width: 100%;    
      overflow-y: scroll;     
      -webkit-overflow-scrolling: touch;
    }
    .tab-box{
      display: flex;
      background: rgb(255,255,255);
      border-radius: 16px 16px 0 0;
      &-text{
        position: absolute;
        display: flex;
        justify-content: space-between;
        width: 100%;
        font-weight: 500;
        font-size: 16px;
        color: #222222;
        line-height: 22px;
      }
      .tab-box-text-isActive{
        color: #1277FF;
      }
    }
  }
  &-text {
    font-size: 18px;
    color: #131D3F;
    line-height: 25px;
    font-weight: 600;
    display: flex;
    width: 100%;
    justify-content: space-between;
    align-items: center;
    padding: 0 4px;
  }
}

.submit-btn {
  background-color: #1277ff;
  color: #fff !important;
  font-size: 16px;
  font-weight: bold;
  letter-spacing: 1px;
  color: #000;

  .tips {
    position: absolute;
    $width: 120px;
    width: $width;
    top: -0.225 * $width * 0.9;
    height: 0.225 * $width;
    background: url(src/assets/images/home/btn-tips.png) no-repeat;
    background-size: 100% 100%;
  }

  .pointer {
    position: absolute;
    right: calc(10% - 0px);
    top: calc(50% - 4px);
    z-index: 1;

    img {
      position: abs;
      z-index: 1;
      animation: scale-anm 2s infinite;
    }
  }
}

@keyframes scale-anm {
  0% {
    transform: scale(1);
  }

  25% {
    transform: scale(1.2);
  }

  50% {
    transform: scale(1);
  }

  75% {
    transform: scale(1.2);
  }

  100% {
    transform: scale(1);
  }
}
</style>